package cn.edu.zafu.bigdata.lhff;

public class ArrayIndexOutOfBoundsExample {
    public static int getElement(int[] arr, int index){
        if (index < 0 || index >= arr.length){
            throw new ArrayIndexOutOfBoundsException("错误:索引超出数组范围");
        }
        return arr[index];
    }
    public static void main(String[] args){
        int[] arr = {1, 2, 3, 4, 5};
        try{
            int result = getElement(arr, 10);
            System.out.println("数组元素:" + result);
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println(e.getMessage());
        }
    }
}
